// 数组

use std::io;

fn main() {
    let arr = [3; 5]; // 元素类型是基础类型，复合类型则不能直接COPY
    let strs:[String; 5] = std::array::from_fn(|_i| String::from("你好！"));
    println!("{:?}", strs);

    println!("请输入数组索引");
    let mut index = String::new();
    io::stdin()
        .read_line(&mut index)
        .expect("输入错误");

    let index: usize = index.trim().parse()
        .expect("请输入整数");

    println!("索引 {} 值是：{}", index, arr[index]);

    {
        
        let one = [1, 2, 3];// 自动推导类型
        let two:[u8; 3] = [1, 2, 3];
        let blank1 = [0; 3];
        let blank2: [u8; 3]=[0;3];

        let arrs:[[u8; 3];4] = [one, two, blank1, blank2];
        for a in &arrs { // 这里采用引用
            println!("{:?}", a);

            // 把 a 转换为迭代器
            for e in a.iter() { // 也可以直接： for e in a {}
                print!("\t{} + 10 = {}", e, e +10);
            }

            let mut sum = 0;
            for i in 0..a.len() { // 0..a.len()是语法糖，相当于0到a.len()-1的数组
                sum += a[i];
            }
            println!("\n\t{:?} = {}", a, sum);
        }
    }
}